<template>
  <el-dialog title="校区续费" :close-on-click-modal="false" :visible.sync="visible" class="cu-dialog cu-dialog_center"
    lock-scroll width="800px">
    <el-row :gutter="15" class="main" :style="{margin: '0 auto',width:'100%'}">
      <el-form ref="elForm" :model="dataForm" size="small" label-width="100px" label-position="right" :rules="rules">
        <el-col :span="12">
          <el-form-item label="开始日期" prop="startDate">
            <el-date-picker v-model="dataForm.startDate" placeholder="请选择" clearable required :style='{"width":"100%"}'
              type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="结束日期" prop="endDate">
            <el-date-picker v-model="dataForm.endDate" placeholder="请选择" clearable required :style='{"width":"100%"}'
              type='datetime' format="yyyy-MM-dd HH:mm:ss" value-format="timestamp">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="应收金额" prop="receivable">
            <el-input v-model="dataForm.receivable" disabled :style='{"width":"100%"}'>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="实收金额" prop="actual">
            <el-input v-model="dataForm.actual" placeholder="请输入实收金额" clearable required :style='{"width":"100%"}'>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="续约政策" prop="policy">
            <el-input v-model="dataForm.policy" placeholder="请输入续约政策" show-word-limit clearable required
              :style='{"width":"100%"}' type='textarea' :autosize='{"minRows":4,"maxRows":4}'>
            </el-input>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">{{$t('common.cancelButton')}}</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :loading="loading">
        {{$t('common.confirmButton')}}</el-button>
    </span>
  </el-dialog>
</template>
<script>
import { getCampusInfo, updateCampusName } from '@/api/campus/campus'
export default {
  components: {},
  props: [],
  data () {
    return {
      loading: false,
      visible: false,
      dataForm: {
        id: '',
        startDate: undefined,
        shortName: undefined,
        newFullName: undefined,
        newShortName: undefined,
        notes: undefined,
      },
      rules: {
        newFullName: [{
          required: true,
          message: '请输入更名后校区全称',
          trigger: 'blur'
        }],
        newShortName: [{
          required: true,
          message: '请输入更名后校区简称',
          trigger: 'blur'
        }],
        notes: [{
          required: true,
          message: '请输入原因/备注',
          trigger: 'blur'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created () {
  },
  mounted () {
  },
  methods: {
    goBack () {
      this.$emit('refresh')
    },
    init (id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['elForm'].resetFields();
        if (this.dataForm.id) {
          getCampusInfo(this.dataForm.id).then(res => {
            this.dataForm = res.data;
          })
        }
      })
    },
    dataFormSubmit () {
      this.$refs['elForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          updateCampusName(this.dataForm).then((res) => {
            this.loading = false
            this.$message({
              message: res.msg,
              type: 'success',
              duration: 1000,
              onClose: () => {
                this.visible = false
                this.$emit('refresh', true)
              }
            })
          })
        }
      })
    },
  }
}
</script>
      